perf: Speed up IN segment condition evaluation#295
Merged
Conversation
Cache the parsed IN-condition value set via lru_cache on the str path and use a frozenset for membership checks. Also short-circuit the JSON parse attempt for values that don't start with "[" — plain comma- separated strings skip json.loads entirely. Adds IN-condition contexts (JSON array form, comma-separated, and native list) to the codspeed benchmark so future changes to IN stay measured. beep boop
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against fbc5641 |
HEAD Temporary pin so CI can run against the bracketed-invalid-JSON CSV fallback test case that covers the new `except ValueError` branch in `_parse_in_values_str`. Will be bumped to the next release tag once Flagsmith/engine-test-data#50 merges. beep boop
Moves the submodule off the temporary PR-branch pin to the tagged release that includes the bracketed-invalid-JSON CSV fallback test case (Flagsmith/engine-test-data#50). beep boop
Zaimwa9
approved these changes
Apr 24, 2026
Contributor
Zaimwa9
left a comment
There was a problem hiding this comment.
Approving as I have an unsure minor defensive comment
khvn26
added a commit
to Flagsmith/flagsmith-python-client
that referenced
this pull request
Apr 24, 2026
Picks up the IN segment-condition evaluation speedup (Flagsmith/flagsmith-engine#295), which cuts per-IN-condition latency on segment walks by roughly 30%. Complementary to the lazy identity evaluation added in this PR — most customer envs will benefit from both. beep boop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_get_in_values()and cache the string-form parse withlru_cache, returning afrozensetfor O(1) membership.json.loadsattempt entirely when the value doesn't start with[— plain comma-separated strings go straight tosplit(","), avoiding a try/except on every first evaluation.except ValueErrorbranch in_parse_in_values_str.Local wall-clock: IN-only eval ~2.29 μs → ~1.58 μs per call (~30% faster) across the benchmark contexts; cold-path parse ~2.1× faster on non-JSON strings.